<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class VirtualLabs_Admin_Permiso {
    const TABLE_NAME = "permiso_rol";
    /**
     * Devuelve permisos segun un criterio.
     * @param type $fields campos a retornar
     * @param type $where criterio de busqueda
     * @throws Exception
     */
    public function getPermisos($fields = array(), $where = array()) {
        $db = Zend_Db_Table::getDefaultAdapter();
        $select = $db->select()->from("permiso", $fields);
        foreach ($where as $key => $value) {
            $select->where("$key {$value['criteria']} ?", $value['value']);
        }
        try {
            return $db->fetchAll($select);
        } catch (Exception $e) {
            $logger = Zend_Registry::get(VirtualLabs_Exception::ERROR_LOG);
            $logger->err($e->getMessage());
            $logger->err($e->getTraceAsString());
            throw $e;
        }
    }
    
    /*
     * Devuelve el primer registro segun un criterio
     * @param type $fields campos a retornar
     * @param type $where criterio de busqueda
     * @throws Exception 
     */
    public function getPermiso($fields = array(), $where = array()) {
        $db = Zend_Db_Table::getDefaultAdapter();
        $select = $db->select()->from("permiso", $fields);
        foreach ($where as $key => $value) {
            $select->where("$key {$value['criteria']} ?", $value['value']);
        }
        try {
            return $db->fetchRow($select);
        } catch (Exception $e) {
            $logger = Zend_Registry::get(VirtualLabs_Exception::ERROR_LOG);
            $logger->err($e->getMessage());
            $logger->err($e->getTraceAsString());
            throw $e;
        }
    }
}
?>
